//
//  OrderCell.m
//  Japanese+
//
//  Created by Jame on 15/10/21.
//  Copyright © 2015年 SSIC. All rights reserved.
//

#import "OrderCell.h"
#import "OrderModel.h"

@implementation OrderCell

- (void)awakeFromNib {
    // Initialization code
}

- (void)setCellWithModel:(NSArray *)model WithIndexPath:(NSIndexPath *)index
{
    OrderData *data = model[index.row];
    self.nameLabel.text = data.mName;
    self.titleLabel.text = data.course_name;
    self.typeLabel.text = data.have_class_way;
    [self.headImage sd_setImageWithURL:[NSURL URLWithString:data.imgUrl] placeholderImage:ECIMAGENAME(@"header.png")];
    self.headImage.clipsToBounds = YES;
    self.headImage.layer.cornerRadius = 65/2;
    
    NSDateFormatter *timeFormatter = [[NSDateFormatter alloc] init];
    [timeFormatter setDateFormat:@"HH:mm"];
    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
    [dateFormatter setDateFormat:@"yyyy-MM-dd"];
    NSString *date = [dateFormatter stringFromDate:[NSDate dateWithTimeIntervalSince1970:[data.class_time integerValue]/1000]];
    NSString *start = [timeFormatter stringFromDate:[NSDate dateWithTimeIntervalSince1970:[data.class_time integerValue]/1000]];
    NSString *end = [timeFormatter stringFromDate:[NSDate dateWithTimeInterval:60*60 sinceDate:[NSDate dateWithTimeIntervalSince1970:[data.class_time integerValue]/1000]]];
    NSString *dateString = [NSString stringWithFormat:@"%@   %@-%@",date,start,end];

    self.timeLabel.text = dateString;
    
    self.priceLabel.text = data.price;
    self.distanceLabel.text = [NSString stringWithFormat:@"%@KM",data.distance];
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
